<?php

/**
 * FactureAvoirFournesseur filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseFactureAvoirFournesseurFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'date'                       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'reference'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'observation'                => new sfWidgetFormFilterInput(),
      'taux_remise'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'statut'                     => new sfWidgetFormChoice(array('choices' => array('' => '', 'Reglée' => 'Reglée', 'Non Reglée' => 'Non Reglée', 'Partiellement Reglée' => 'Partiellement Reglée'))),
      'total_ht'                   => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'total_remise'               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'total_tva'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'total_ttc'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'rest'                       => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'timbre'                     => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'date_validite'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'duree_validite'             => new sfWidgetFormFilterInput(),
      'cloture'                    => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'domaine'                    => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'mode_paiement'              => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'taux_escompte'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'num_attestation_timbre'     => new sfWidgetFormFilterInput(),
      'confirme'                   => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'valider'                    => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'brouillon'                  => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'date_changement_etat'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'avance_sur_impot'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'total_fodec'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'journal_caisse'             => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'quantite_retourner'         => new sfWidgetFormFilterInput(),
      'fournesseur_id'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Fournisseur'), 'add_empty' => true)),
      'created_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'factures_fournisseurs_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'FactureFournisseur')),
    ));

    $this->setValidators(array(
      'date'                       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'reference'                  => new sfValidatorPass(array('required' => false)),
      'observation'                => new sfValidatorPass(array('required' => false)),
      'taux_remise'                => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'statut'                     => new sfValidatorChoice(array('required' => false, 'choices' => array('Reglée' => 'Reglée', 'Non Reglée' => 'Non Reglée', 'Partiellement Reglée' => 'Partiellement Reglée'))),
      'total_ht'                   => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'total_remise'               => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'total_tva'                  => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'total_ttc'                  => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'rest'                       => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'timbre'                     => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'date_validite'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'duree_validite'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'cloture'                    => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'domaine'                    => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'mode_paiement'              => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'taux_escompte'              => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'num_attestation_timbre'     => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'confirme'                   => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'valider'                    => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'brouillon'                  => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'date_changement_etat'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'avance_sur_impot'           => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'total_fodec'                => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'journal_caisse'             => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'quantite_retourner'         => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'fournesseur_id'             => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Fournisseur'), 'column' => 'id')),
      'created_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'factures_fournisseurs_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'FactureFournisseur', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('facture_avoir_fournesseur_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addFacturesFournisseursListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.FactureFournesseurAvoirFournesseur FactureFournesseurAvoirFournesseur')
      ->andWhereIn('FactureFournesseurAvoirFournesseur.facture_frournesseur_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'FactureAvoirFournesseur';
  }

  public function getFields()
  {
    return array(
      'id'                         => 'Number',
      'date'                       => 'Date',
      'reference'                  => 'Text',
      'observation'                => 'Text',
      'taux_remise'                => 'Number',
      'statut'                     => 'Enum',
      'total_ht'                   => 'Number',
      'total_remise'               => 'Number',
      'total_tva'                  => 'Number',
      'total_ttc'                  => 'Number',
      'rest'                       => 'Number',
      'timbre'                     => 'Boolean',
      'date_validite'              => 'Date',
      'duree_validite'             => 'Number',
      'cloture'                    => 'Boolean',
      'domaine'                    => 'Boolean',
      'mode_paiement'              => 'Boolean',
      'taux_escompte'              => 'Number',
      'num_attestation_timbre'     => 'Number',
      'confirme'                   => 'Boolean',
      'valider'                    => 'Boolean',
      'brouillon'                  => 'Boolean',
      'date_changement_etat'       => 'Date',
      'avance_sur_impot'           => 'Number',
      'total_fodec'                => 'Number',
      'journal_caisse'             => 'Boolean',
      'quantite_retourner'         => 'Number',
      'fournesseur_id'             => 'ForeignKey',
      'created_at'                 => 'Date',
      'updated_at'                 => 'Date',
      'factures_fournisseurs_list' => 'ManyKey',
    );
  }
}
